<?php
/* 路线图相关操作控制器 */

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class RoadMapController extends HomeController
{
    //修改
    public function update(Request $request)
    {
        try {
            //接受参数
            $id = $request->input('id');

            //接受参数并组装成数组
            $data = [];
            $data['url'] = $request->input('path');

            //修改数据到数据表
            DB::table('road_map')->where('id', $id)->update($data);

            return response()->json(['code' => HTTP_OK,'message' => HTTP_OK_MESSAGE]);
        } catch (\Exception $e) {
            // 记录错误日志
            Log::error('修改公告失败: ' . $e->getMessage());
            return response()->json([
                'code' => HTTP_ERROR,
                'message' => '修改公告失败',
                'data' => null
            ]);
        }
    }

    //详情
    public function detail(Request $request)
    {
        try {
            //接受参数
            $id = $request->input('id');
            $field = ['title', 'content', 'is_top'];
            //根据id查询详情
            $data = DB::table('road_map')->where('id', $id)->select($field)->first();

            return response()->json(['code' => HTTP_OK,'message' => HTTP_OK_MESSAGE,'data' => $data]);
        } catch (\Exception $e) {
            // 记录错误日志
            Log::error('获取公告详情失败: ' . $e->getMessage());
            return response()->json([
                'code' => HTTP_ERROR,
                'message' => '获取公告详情失败',
                'data' => null
            ]);
        }
    }

}
